using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using RideMe.Core.Properties;

namespace RideMe.Core
{
    public static class DocumentManager
    {
        public static string GetDocumentText(string path)
        {
            CheckFile(path);

            return File.ReadAllText(path);
        }

        public static void SaveDocument(string path, string contents)
        {
            File.WriteAllText(path, contents);
        }

        public static void CreateDirectory(string path)
        {
            Directory.CreateDirectory(path);
        }
        
        public static void DeleteDocument(string path)
        {
            CheckFile(path);

            File.Delete(path);
        }

        public static void DeleteDirectory(string path)
        {
            if (!Validator.ValidDirectory(path))
            {
                throw new IOException(Resources.DirectoryDoesNotExist);
            }

            Directory.Delete(path, true);
        }

        private static void CheckFile(string path)
        {
            if (!Validator.ValidDocument(path))
            {
                throw new IOException(Resources.FileDoesNotExist);
            }
        }

    }
}
